import axios from 'axios';
import {BASE_API} from '../config/base.js';


axios.defaults.baseURL = BASE_API;
axios.defaults.headers.common['Authorization'] = '';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';


/**
* get方法，对应get请求
* @param {String} url [请求的url地址] 
 * @param {Object} params [请求时携带的参数] 
 * */ 


export function get(url, params={}, headers={}) {
  
    return new Promise((resolve, reject) => { 
       axios.get(url, { params, headers }).then(res => { 
           resolve(res)
       }).catch(err => {
           reject(err) 
}) 
})
}


/**
 * post方法，对应post请求 
 * * @param {String} url [请求的url地址] 
 * * @param {Object} params [请求时携带的参数] 
 **/ 


export function post(url, params, headers) { 
    return new Promise((resolve, reject) => { 
         axios.post(url, params, headers).then((res) => { 
             resolve(res)
        }).catch((err) => {
            // debugger
             reject(err) 
}) 
 }) }